package com.quan.common.handler.amqp.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.quan.common.base.constant.CommonConstant;
import com.quan.common.utils.RandomUitl;
import com.quan.system.entity.SystemLog;

/**
 * 消息生产端-日志记录
 * @author yhaoquan
 *
 */
@Component
public class LoggerMessageProducer {
	
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private RabbitTemplate rabbitTemplate ;
	
	/**
	 * 发送日志消息
	 * @param entity
	 */
	public void sender(SystemLog entity) {
		logger.info("-----------------------消息生产端----------------------------");
		//发送消息(交换机 exchange, 路由键 routingKey, 消息体内容, 消息唯一ID)
		this.rabbitTemplate.convertAndSend(CommonConstant.EXCHANGE_TOPIC_LOGGER, CommonConstant.QUEUE_TOPIC_LOGGER, entity, new CorrelationData(RandomUitl.uuid()));
		logger.info("发送日志消息==>>{}", JSON.toJSONString(entity));
	}

	

}
